<?php
namespace Builder;

use Builder\BuilderInterface;

/**
 * Mp3建造者
 */
class Mp3Builder implements BuilderInterface
{
    private $_name = '';
    private $_cpu = '';
    private $_ram = '';
    private $_storage = '';
    private $_os = '';

    public function __construct($name = '', $hardware = [], $software = [])
    {
        $this->_name = $name;
        $this->hardware($hardware);//构建硬件
        $this->software($software);//构建软件
    }

    /**
     * 构建硬件
     * @param  array  $hardware [description]
     * @return [type]           [description]
     */
    public function hardware($hardware = [])
    {
        //创建cpu
        $hardwareCpu = new HardwareCpu();
        $this->_cpu = $hardwareCpu->produce($hardware['cpu']);

        //创建内存
        $hardwareRam = new HardwareRam();
        $this->_ram = $hardwareRam->produce($hardware['ram']);

        //创建存储
        $hardwareStorage = new HardwareStorage();
        $this->_storage = $hardwareStorage->produce($hardware['storage']);
    }

    /**
     * 构建软件
     * @param  array  $software [description]
     * @return [type]           [description]
     */
    public function software($software = [])
    {
        //创建操作系统
        $softwareOs = new SoftwareOs();
        $this->_os = $softwareOs->produce($software['os']);
    }

    /**
     * 返回Mp3对象
     * @return [type] [description]
     */
    public function getResult()
    {
        $str = '';
        $str .= $this->_name . '配置如下: ' . PHP_EOL;
        $str .= 'CPU核心数: '. $this->_cpu . '核';
        $str .= '内存大小: '. $this->_ram . 'G';
        $str .= '存储大小: '. $this->_storage . 'G';
        $str .= '操作系统: '. $this->_os . PHP_EOL;

        echo $str;
    }
}